#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>

using namespace std;

typedef long long LL;
const int maxK = 127;
const int maxM = 100010;
int tot,a[3];
bool vis[501];

struct TreeNode
{
    TreeNode *next[maxK];
    TreeNode *fail;
    bool accept;
    int count;
    int id;
    void init(TreeNode *fl, int i)
    {
        accept = false;
        fail = fl;
        id = i;
        count = 0;
        memset(next, 0, sizeof(next));
    }
};

struct AC
{
    TreeNode *root;    
    TreeNode *queue[maxM];
    int C;
    TreeNode* newNode()
    {
        TreeNode *res = new TreeNode;
        res->init(root, C);
    //    nodes[C++] = res;
        return res;
    }
    void init()
    {
        C = 0;
        root = NULL;
        root = newNode();
    }
    void insert(char str[],int cnt)
    {
        TreeNode *current = root;
        for (int i = 0; str[i]; i++)
        {
            if (!current->next[str[i]])
                current->next[str[i]] = newNode();
            current = current->next[str[i]];
        }
        current->count=cnt;
        current->accept = true;//be careful of the repetation
    }
    void finish()//Build Fail
    {
        int head = 0, tail = 0;
        queue[tail++] = root;
        while (head != tail)
        {
            TreeNode *current = queue[head++];
            for (int i = 0; i < maxK; i++)
            {
                if (!current->next[i])
                    continue;
                queue[tail++] = current->next[i];
                if (current == root)
                    continue;
                for (TreeNode *t = current->fail; t; t = t->fail)
                {
                    if (t->next[i])
                    {
                        current->next[i]->fail = t->next[i];
                        current->next[i]->accept |= t->next[i]->accept;
                        break;
                    }
                }
            }
        }
    }
    int match(char str[])
    {
		int find=0;
        TreeNode *current = root;
        for (int i = 0; str[i]; i++)
        {
            int flag = 1;
            for (TreeNode *t = current; t; t = t->fail)
            {
                TreeNode *c = t->next[str[i]];
                if (c)
                {
                    if (flag)
                    {
                        flag = 0;
                        current = c;
                    }
                    if (c->accept&&!vis[c->count])
                    {
                        a[find]=c->count;
						vis[c->count]=1;
						find++;
                    }
                    else
                        break;
                }
            }
            current = flag ? root : current;
        }
		return find;
    }
}orz;
int main()
{
    int m,n;       
    orz.init();
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
    {
		char ch[201];
        scanf("%s",ch);
        orz.insert(ch,i);
    }
	orz.finish();
	scanf("%d",&m);
	tot=0;
	for(int i=1;i<=m;i++)
	{
		memset(vis,0,sizeof(vis));
		char s[10010];
        scanf("%s",s);
		a[0]=a[1]=a[2]=0;
        int nn=orz.match(s);
		if(nn>0)
		{
			sort(a,a+nn);
			tot++;
			printf("web %d:",i);
			for(int i=0;i<nn;i++)
				printf(" %d",a[i]);
			printf("\n");
		}
	}
	printf("total: %d\n",tot);
    return 0;
}
